/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2013
 */

package org.teacup.eightdays.model;

import javax.persistence.*;

import org.hibernate.annotations.GenericGenerator;

import javax.validation.constraints.*;
import org.hibernate.validator.constraints.*;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import org.teacup.eightdays.model.*;
import org.teacup.eightdays.dao.*;
import org.teacup.eightdays.service.*;
import org.teacup.eightdays.vo.query.*;

/**
 * @author Abner email:521yexu2008(a)163.com
 * @version 1.0
 * @since 1.0
 */

@Entity
@Table(name = "department")
public class Department extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "Department";
	public static final String ALIAS_DEPARTMENT_ID = "ID";
	public static final String ALIAS_SCHOOL_ID = "所在学校ID";
	public static final String ALIAS_DEPARTMENT_NAME = "院系名称";
	public static final String ALIAS_PARENT_ID = "父级ID";
	
	//date formats
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
    /**
     * ID       db_column: department_id 
     */ 	
	
	private java.lang.Long departmentId;
    /**
     * 所在学校ID       db_column: school_id 
     */ 	
	
	private java.lang.Long schoolId;
    /**
     * 院系名称       db_column: department_name 
     */ 	
	@Length(max=200)
	private java.lang.String departmentName;
    /**
     * 父级ID       db_column: parent_id 
     */ 	
	
	private java.lang.Long parentId;
	//columns END


	public Department(){
	}

	public Department(
		java.lang.Long departmentId
	){
		this.departmentId = departmentId;
	}

	

	public void setDepartmentId(java.lang.Long value) {
		this.departmentId = value;
	}
	
	@Id @GeneratedValue(generator="custom-id")
	@GenericGenerator(name="custom-id", strategy = "increment")
	@Column(name = "department_id", unique = true, nullable = false, insertable = true, updatable = true, length = 19)
	public java.lang.Long getDepartmentId() {
		return this.departmentId;
	}
	
	@Column(name = "school_id", unique = false, nullable = true, insertable = true, updatable = true, length = 19)
	public java.lang.Long getSchoolId() {
		return this.schoolId;
	}
	
	public void setSchoolId(java.lang.Long value) {
		this.schoolId = value;
	}
	
	@Column(name = "department_name", unique = false, nullable = true, insertable = true, updatable = true, length = 200)
	public java.lang.String getDepartmentName() {
		return this.departmentName;
	}
	
	public void setDepartmentName(java.lang.String value) {
		this.departmentName = value;
	}
	
	@Column(name = "parent_id", unique = false, nullable = true, insertable = true, updatable = true, length = 19)
	public java.lang.Long getParentId() {
		return this.parentId;
	}
	
	public void setParentId(java.lang.Long value) {
		this.parentId = value;
	}
	
	
	private Set memberinfos = new HashSet(0);
	public void setMemberinfos(Set<Memberinfo> memberinfo){
		this.memberinfos = memberinfo;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "department")
	public Set<Memberinfo> getMemberinfos() {
		return memberinfos;
	}
	
	private School school;
	public void setSchool(School school){
		this.school = school;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "school_id",nullable = false, insertable = false, updatable = false) 
	})
	public School getSchool() {
		return school;
	}

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("DepartmentId",getDepartmentId())
			.append("SchoolId",getSchoolId())
			.append("DepartmentName",getDepartmentName())
			.append("ParentId",getParentId())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getDepartmentId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof Department == false) return false;
		if(this == obj) return true;
		Department other = (Department)obj;
		return new EqualsBuilder()
			.append(getDepartmentId(),other.getDepartmentId())
			.isEquals();
	}
}

